package com.whitedust.top80;

/**
 *
 * @author A
 * @since 2025/11/15 23:30
 */

public class Top77 {
    public boolean searchMatrix(int[][] matrix, int target) {
        int m = matrix.length;
        int n = matrix[0].length;
        int i = 0;
        int j = n - 1;
        //从右上角开始比较，比当前值大则一定在当前值的下方
        //比当前值小一定在当前值的左侧
        while (i < m && j >= 0) {
            if (matrix[i][j] < target) i++;
            else if (matrix[i][j] > target) {
                j--;
            } else {
                return true;
            }
        }
        return false;
    }
}
